sqrt(x = 16)[1] 4
Field Ecology
Oct 6, 2025
R is an open-source software environment for statistical computing and graphics, popular among ecologist and data scientist.
There’s almost nothing you can’t do with R and RStudio!1
Since R does not have a graphical user interface (GUI) for point-and-click interactions like Excel or SPSS, most people use an Integrated Development Environment (IDE) called RStudio.
Before you start writing code, you need to open an R Script file, this is where you’ll be able to save code for later.
A function is a reusable piece of code that performs a task.
Functions often take inputs (called arguments or parameters) and return an output.
For example:
Here, sqrt() is the function, 16 is the argument, and the output is 4.
You can think of a function like a math function:
In math: \(y = f(x)\)
In R: f(x)
The function log() takes 100 as input and returns its logarithm.
Packages are collections of functions, data, and documentation bundled together
They extend R so you can do tasks like data wrangling, visualization, or machine learning.
R comes with a set of base packages, but thousands of additional packages are available through repositories like CRAN and GitHub.
Examples of popular packages:
To install a package, type the following commands in the Console at the bottom of RStudio and press Enter after each one:
Or navigate to Tools > Install Packages … and type the packages you want to install
To install a package, type the following commands in the Console at the bottom of RStudio and press Enter after each one:
Or navigate to Tools > Install Packages … and type the packages you want to install
This will download and install:
After installation, load the packages into your R session by typing these lines of code into your R Script:
You will write your code in the script but it won’t run automatically
You can position your cursor on any line of code in your script and click the Run button and your code will be sent to the console and run.
If you want to run multiple lines, you can highlight a section of code, click Run, and the entire highlighted section will be sent to the console.
You can type code directly into the console, but the code and output is not saved.
A data frame is one of the most common ways to store data in R. Think of it like a spreadsheet or a table:
Each row is an observation (like one student, one site, or one day).
Each column is a variable (like name, age, or temperature).
Almost every dataset you import into R (CSV, Excel, database) becomes a data frame.
Functions in R (and packages like dplyr and ggplot2) are designed to work naturally with data frames
Or in the console:
spc_tbl_ [80 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ Watershed: chr [1:80] "004b" "004b" "004b" "004b" ...
$ Plot : chr [1:80] "a1" "a2" "a3" "a4" ...
$ N : num [1:80] 27 24 23 24 32 26 27 33 26 28 ...
$ FQI : num [1:80] 22.9 21.3 20.7 21.9 23.5 ...
$ D : num [1:80] 7.98 6.82 5.58 7 8.6 ...
$ Bison : chr [1:80] "No Graze" "No Graze" "No Graze" "No Graze" ...
$ BurnCycle: num [1:80] 4 4 4 4 4 4 4 4 4 4 ...
- attr(*, "spec")=
.. cols(
.. Watershed = col_character(),
.. Plot = col_character(),
.. N = col_double(),
.. FQI = col_double(),
.. D = col_double(),
.. Bison = col_character(),
.. BurnCycle = col_double()
.. )
- attr(*, "problems")=<externalptr>
Lets calculate the mean and standard deviation of FQI in each bison group
The tidyverse pipe (%>%) is a shortcut that makes R code easier to read and write when you want to do multiple steps in a row.
%>% takes the thing on the left-hand side and passes it as the first argument to the function on the right-hand side
In RStudio, the keyboard shortcut for inserting the tidyverse pipe (%>%) is:
Windows/Linux: Ctrl + Shift + M
Mac: Cmd + Shift + M
In ggplot2, you build a plot in layers.
In ggplot2, you build a plot in layers.
Teaches foundational coding and data science skills to researchers worldwide, all lessons are published online.
The Carpentries Workshops @ KU:
Spring 2026 - EVRN 420: Environmental Data Science W/ Dr. Zimmerman.